//
//  ListTableView.m
//  StationManager
//
//  Created by 张佳强 on 17/3/6.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "ListTableView.h"

@implementation ListTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.backgroundColor = [UIColor blackColor];
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}

#pragma TableView - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString * iden = @"iden";
    UITableViewCell * cell = [self dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
    }
    cell.contentView.backgroundColor = [UIColor blackColor];
    cell.contentView.alpha = 0.6;
    cell.textLabel.text = self.dataArray[indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont systemFontOfSize:12.0];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self deselectRowAtIndexPath:indexPath animated:YES];
    if ([self.vcName isEqualToString:@"Maintain"]) {
      
        NSDictionary * dict = @{@"section":[NSString stringWithFormat:@"%ld",(long)self.sectionTag],@"row":[NSString stringWithFormat:@"%ld",(long)self.rowTag],@"data":self.dataArray[indexPath.row]};
        if (self.tableViewTag == 100) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"changeData" object:dict];
        }
        if (self.tableViewTag == 200) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"changeUnormalData" object:dict];
        }
    }
    if ([self.vcName isEqualToString:@"Task"]) {
        
        NSDictionary * dict = @{@"buttonId":[NSString stringWithFormat:@"%i",self.buttonId],@"data":self.dataArray[indexPath.row]};
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeButtonTitle" object:dict];
    }
    
    if ([self.vcName isEqualToString:@"Commit"]) {
        NSString * title = self.dataArray[indexPath.row];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setButtonTitle" object:title];
    }
}

@end
